//***************************** 键值定义 *****************************
var ROC_IRKEY_NUM0 = 48 /* 0x0030, 数字键0 */
var ROC_IRKEY_NUM1 = 49 /* 0x0031, 数字键1 */
var ROC_IRKEY_NUM2 = 50 /* 0x0032, 数字键2 */
var ROC_IRKEY_NUM3 = 51 /* 0x0033, 数字键3 */
var ROC_IRKEY_NUM4 = 52 /* 0x0034, 数字键4 */
var ROC_IRKEY_NUM5 = 53 /* 0x0035, 数字键5 */
var ROC_IRKEY_NUM6 = 54 /* 0x0036, 数字键6 */
var ROC_IRKEY_NUM7 = 55 /* 0x0037, 数字键7 */
var ROC_IRKEY_NUM8 = 56 /* 0x0038, 数字键8 */
var ROC_IRKEY_NUM9 = 57 /* 0x0039, 数字键9 */
//
 var ROC_IRKEY_UP = 38 /*0x0026, 遥控器上的向上键*/
 var ROC_IRKEY_DOWN = 40 /*0x0028, 遥控器上的向下键*/
 var ROC_IRKEY_LEFT = 37 /*0x0025, 遥控器上的向左键*/
 var ROC_IRKEY_RIGHT = 39 /*0x0027, 遥控器上的向右键*/
//var ROC_IRKEY_UP = 51 /* 0x0026, 遥控器上的向上键 */
//var ROC_IRKEY_DOWN = 52 /* 0x0028, 遥控器上的向下键 */
//var ROC_IRKEY_LEFT = 49 /* 0x0025, 遥控器上的向左键 */
//var ROC_IRKEY_RIGHT = 50 /* 0x0027, 遥控器上的向右键 */
var ROC_IRKEY_SELECT = 13 /* 0x000D, 遥控器上的确定键,即OK */
 var ROC_IRKEY_BACK = 8 /*0x0280, 遥控器上的返回键,即TOGGLE*/
//var ROC_IRKEY_BACK = 53 /* 0x0280, 遥控器上的返回键,即TOGGLE */

var ROC_IRKEY_EXIT = 1285 /* 0x0119, 取消/退出键,即CANCEL */
var ROC_IRKEY_CHANNEL_DOWN = 257 /* 0x01AC, 遥控器上的频道减少键 */
var ROC_IRKEY_CHANNEL_UP = 258 /* 0x01AB, 遥控器上的频道增加键 */
var ROC_IRKEY_PAGE_UP = 33 /* 0x0021, 遥控器上的向上翻页键 */
var ROC_IRKEY_PAGE_DOWN = 34 /* 0x0022, 遥控器上的向下翻页键 */
var ROC_IRKEY_VOLUME_UP = 259 /* 0x01BF, 遥控器上的音量增大键 */
var ROC_IRKEY_VOLUME_DOWN = 260 /* 0x01C0, 遥控器上音量减小键 */
var ROC_IRKEY_VOLUME_MUTE = 261 /* 0x01C1, 遥控器上的静音键 */
// var ROC_IRKEY_TRACK = 262 /*0x0197, 遥控器上的声道键,即AUDIO*/
var ROC_IRKEY_TRACK = 0x0506 /* 0x0506, 遥控器上的支付键提到声道键 */
var ROC_IRKEY_RED = 275 /* 0x0193, 代表红色按键 直播 */
var ROC_IRKEY_GREEN = 276 /* 0x0196, 代表绿色按键 回看 */
var ROC_IRKEY_YELLOW = 277 /* 0x0194, 代表黄色按键 点播 */
var ROC_IRKEY_BLUE = 278 /* 0x0195, 代表蓝色按键 信息 */
var ROC_IRKEY_REWIND = 1282 /* 快退 */
var ROC_IRKEY_FAST = 1283 /* 快进 */
var ROC_IRKEY_STOP = 1284 /* 遥控器上的停止键 */
var ROC_IRKEY_PLAY = 263 /* 0x0107, 遥控器上的播放暂停键 */
var POC_IRKEY_INDEX = 181 /* 首页 */
// var ROC_IRKEY_POWER =256 /*0xFFFF, 遥控器上的指示关机与开机键----旧盒子程序20120612*/
var ROC_IRKEY_POWER = 1279 /* 0x04FF, 遥控器上的指示关机与开机键-----新盒子程序20120612 */
var ROC_IRKEY_CIRCULATE = 280 /* 遥控器上的循环键 */
var ROC_IRKEY_LOCATION = 271 /* 遥控器定位键 */
var ROC_IRKEY_SET = 285 /* 遥控器设置键 */

// 暂无k
var ROC_IRKEY_MENU = 72 /* 0x01D4, 遥控器上的菜单键 */
var ROC_IRKEY_INFO = 291 /* 0x01C9, 遥控器上的信息键 */
var ROC_IRKEY_EPG = 69 /* 0x01CA, 遥控器上的节目指南键,预告键,即GUIDE */
var ROC_IRKEY_LIKE = 76 /* 0x01CB, 遥控器上的字幕键/频道喜爱键,即TELETEXT */
var ROC_IRKEY_NVOD = 315 /* 0x0283, 遥控器上的卡信息或点播键,交互键, 即CARD_INFO */
var ROC_IRKEY_MAIL = 77 /* 0x0284, 遥控器上的邮件键 */
var ROC_IRKEY_PROGRAM_LIST = 0x0281 /* 0x0281, 遥控器上的频道列表键或咨询键,即PROG_LIST */
var ROC_IRKEY_TV_RADIO = 0x0282 /* 0x0282, 遥控器上的指示"电视/音频广播"键 */
var ROC_IRKEY_GRAY_VOLUME_UP = 245 /* 遥控器上的灰色音量加键 */
var ROC_IRKEY_GRAY_VOLUME_DOWN = 244 /* 遥控器上的灰色音量减键 */
var EVENT_UTILITY = 0x0300 /* IPTV虚拟按键事件 */

var channellistMap = new Dictionary();
 MY_PORTAL_ADDR =getRoot();
//MY_PORTAL_ADDR = '/EPG/getJson?';
//Image_Server_Url = "http://222.221.25.243:6166";
 Image_Server_Url=getRoot();

// 是否使用机顶盒环境
var isServer = true;
try {
	Navigation.disableDefaultNavigation();
} catch (e) {
}

function GetUrlParam(name) {
	// 构造一个含有目标参数的正则表达式对象
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
	// 匹配目标参数
	var r = window.location.search.substr(1).match(reg);
	// 返回参数值
	if (r != null)
		return unescape(r[2]);
	return null;
}
function CheckStrLen(str) {
	var len = 0;
	for ( var i = 0; i < str.length; i++) {
		var a = str.charAt(i);
		if (a.match(/[^\x00-\xff]/ig) != null)
			len += 2;
		else
			len += 1;
	}
	return len;
}
function CutString(str, maxlen) {
	var result = "";
	var len = 0;
	for ( var i = 0; i < str.length; i++) {
		var a = str.charAt(i);
		if (a.match(/[^\x00-\xff]/ig) != null)
			len += 2;
		else
			len += 1;
		if (len <= maxlen) {
			result = result + a;
		} else
			break;
	}
	return result;
}

var Ajax = function() {
	function request(url, opt) {
		function fn() {
		}
		opt = opt || {};
		var async = opt.async !== false, method = opt.method || 'GET', type = opt.type
				|| 'json', encode = opt.encode || 'UTF-8', timeout = opt.timeout || 10000, data = opt.data
				|| null, success = opt.success || fn, failure = opt.failure
				|| fn;
		method = method.toUpperCase();
		if (data && typeof data == 'object') {// 对象转换成字符串键值对
			data = _serialize(data);
		}
		if (method == 'GET' && data) {
			url += (url.indexOf('?') == -1 ? '?' : '&') + data;
			data = null;
		}
		// if(url.indexOf("?") >= 0) {
		// url = url+"&stbNo="+getSTBID();
		// } else {
		// url = url + "?stbNo="+getSTBID();
		// }
		var xhr = function() {
			try {
				return new XMLHttpRequest();
			} catch (e) {
				try {
					return new ActiveXObject('Msxml2.XMLHTTP');
				} catch (e) {
					try {
						return new ActiveXObject('Microsoft.XMLHTTP');
					} catch (e) {
						failure(null, 'create xhr failed', e);
					}
				}
			}
		}();
		if (!xhr) {
			return;
		}
		var isTimeout = false, timer;
		if (async && timeout > 0) {
			timer = setTimeout(function() {
				xhr.abort();
				isTimeout = true;
			}, timeout);
		}
		xhr.onreadystatechange = function() {
			if (xhr.readyState == 4 && !isTimeout) {
				_onStateChange(xhr, type, success, failure);
				clearTimeout(timer);
				xhr = null;
			} else {
			}
		};
		xhr.open(method, url, async);
		if (method == 'POST') {
			xhr.setRequestHeader('Content-type',
					'application/x-www-form-urlencoded;charset=' + encode);
		}

		xhr.send(data);
		return xhr;
	}
	function _serialize(obj) {
		var a = [];
		for ( var k in obj) {
			var val = obj[k];
			if (val.constructor == Array) {
				for ( var i = 0, len = val.length; i < len; i++) {
					a.push(k + '=' + encodeURIComponent(val[i]));
				}
			} else {
				a.push(k + '=' + encodeURIComponent(val));
			}
		}
		return a.join('&');
	}
	function strToJson(str) {
		str = str.replace(/(\n)+|(\r\n)+/g, "<br>");
		var json = eval('(' + str + ')');
		return json;
	}
	function _onStateChange(xhr, type, success, failure) {

		var s = xhr.status, result;

		if (s >= 200 && s < 300) {
			switch (type) {
			case 'text':
				result = xhr.responseText;
				break;
			case 'json':
				result = function(str) {
					try {
						// return JSON.parse(str);
						return strToJson(str);
					} catch (e) {
						try {
							return (new Function('return ' + str))();
						} catch (e) {
							failure(xhr, 'parse json error', e);
						}
					}
				}(xhr.responseText);
				break;
			case 'xml':
				result = xhr.responseXML;
				break;
			}

			// text, 返回空字符时执行success
			// json, 返回空对象{}时执行suceess，但解析json失败，函数没有返回值时默认返回undefined

			typeof result !== 'undefined' && success(result);

			// 请求超时，调用abort后xhr.status为0，但不知为0时是否还有其它的情况
		} else if (s === 0) {
			failure(xhr, 'request timeout');
		} else {
			failure(xhr, xhr.status);
		}
		xhr = null;
	}
	return (function() {
		var Ajax = {
			request : request
		}, types = [ 'text', 'json', 'xml' ];
		for ( var i = 0, len = types.length; i < len; i++) {
			Ajax[types[i]] = function(i) {
				return function(url, opt) {
					opt = opt || {};
					opt.type = types[i];
					return request(url, opt);
				}
			}(i);
		}
		return Ajax;
	})();
}();

// 全局打印信息
function GF_WebPrint(msg) {
	// try{
	// var Extend = new QjyScript();
	// //Extend.exec("SYS_DbgPrint","ovtportal:"+msg);
	// Extend.debug("ovtportal:"+msg);
	// }catch(e){
	//		
	// }
}
function QjyScript() {
	this.debug = function(str) {

	}
	this.exec = function(name, msg) {
		if (name == "SYS_DbgPrint") {
			this.objdiv = document.getElementById("debugdiv");
			if (this.objdiv == null) {// 层不存在
				var divObj = document.createElement("div");
				divObj.innerHTML = '<div id="debugdiv" style="background:#CCC;position:absolute;width:200px;z-index:100;left:50px;top:20px;"></div>';
				document.body.appendChild(divObj);
				// this.objdiv = $("#debugdiv");
			}
			$("#debugdiv").html(msg + "<br>");
			// this.objdiv.innerHTML += msg+"<br>"
		} else if (name == "OvtGetConfig") {
			if (msg == "language") {
				return "eng";
			}
		}
		return "";
	}
	this.debug = function(msg) {
		this.objdiv = document.getElementById("debugdiv");
		if (this.objdiv == null) {// 层不存在
			var divObj = document.createElement("div");
			divObj.innerHTML = '<div id="debugdiv" style="background:#CCC;position:absolute;width:400px;z-index:100;left:50px;top:20px;"></div>';
			document.body.appendChild(divObj);
			// this.objdiv = $("debugdiv");
		}
		$("#debugdiv").html(msg + "<br>");
	}
}
function getDataStr(i) {
	var i = parseInt(i);
	var LSTR_ndate = new Date();
	var LSTR_Year = LSTR_ndate.getFullYear();
	var LSTR_Month = LSTR_ndate.getMonth();
	var LSTR_Date = LSTR_ndate.getDate();
	var uom = new Date(LSTR_Year, LSTR_Month, LSTR_Date);
	uom.setDate(uom.getDate() - i);
	// 取得系统时间的前一天,重点在这里,负数是前几天,正数是后几天
	var LINT_YY = uom.getFullYear();
	var LINT_MM = uom.getMonth();
	LINT_MM++;

	var LSTR_MM = LINT_MM >= 10 ? LINT_MM : ("0" + LINT_MM);
	var LINT_DD = uom.getDate();
	var LSTR_DD = LINT_DD >= 10 ? LINT_DD : ("0" + LINT_DD);
	return LINT_YY + "" + LSTR_MM + "" + LSTR_DD;
}

// 判断为空的函数
function isnull(jsonstr) {
	for ( var key in jsonstr) {
		return false;
	}
	return true;
}

var OVT_media = function() {
	this.id = 0;
	this.myplay = "";
	this.joinChannelFlg = -1;
	this.init = function(screentype, x, y, w, h) {
		this.myplay = new MediaPlayer();
		this.id = this.myplay.getNativePlayerInstanceID();
		// this.myplay.setSingleOrPlaylistMode(0);//0:单媒体(默认值)，1:播放列表
		if (screentype == 1) {// 全屏
			this.myplay.setVideoDisplayMode(1);// 1代表全屏显示
		} else {
			this.myplay.setVideoDisplayMode(0);//
			this.myplay.setVideoDisplayArea(x, y, w, h);
		}
		this.myplay.refreshVideoDisplay();// 设置生效
	}
	this.getInstanceID = function() {// 获取实例--殷腾飞
		this.id = this.myplay.getNativePlayerInstanceID();
	}
	this.seturl = function(url) {// 设计URL
		// 点播-"rtsp://10.160.34.70:6554/;purchaseToken=ovt.com-6210-VOD";
		var mediaStr = this.toJson(url);
		this.myplay.setSingleMedia(mediaStr);
	}
	this.setchannel = function(channelid) {// 直播地址
		if (this.joinChannelFlg == -1) {
			this.myplay.joinChannel(channelid);
			this.joinChannelFlg = 0;
		} else {
			this.myplay.leaveChannel();
			this.myplay.joinChannel(channelid);
		}
	}
	this.leaveChannel = function() {// 停止直播 －－田彦荣
		this.myplay.leaveChannel();
	}
	this.leave = function() {// 停止直播并释放资源 －－田彦荣
		this.myplay.leaveChannel();
		this.myplay.releaseMediaPlayer(this.id);
	}
	this.play = function() {// 播放页面
		this.myplay.playFromStart();
	}
	this.forward = function(pace) {// 快进 8,16,32
		this.myplay.fastForward(pace);
	}
	this.backward = function(pace) {// 快退 -8,-16,-32
		this.myplay.fastRewind(pace);
	}
	this.seek = function(time) {// 跳转时间 秒
		this.myplay.playByTime(1, time, 1);
	}
	this.pause = function(flag) {// flag=1:最后一帧，0：黑场
		this.myplay.pause();
	}
	this.resume = function() {
		this.myplay.resume();
	}
	this.getplaytime = function() {
		return this.myplay.getCurrentPlayTime();
	}
	this.stop = function() {// 停止播放
		this.myplay.stop();
	}
	this.close = function() {// 关闭播放器
		this.myplay.stop();
		this.myplay.releaseMediaPlayer(this.id);
	}
	this.toJson = function(url) {// 返回点播url
		return '[{mediaUrl:"' + url + '",mediaCode: "media1",' + 'mediaType:2,'
				+ 'audioType:1,' + 'videoType:1,' + 'streamType:2,'
				+ 'drmType:1,' + 'fingerPrint:0,' + 'copyProtection:1,'
				+ 'allowTrickmode:1,' + 'startTime:0,' + 'endTime:5000,'
				+ 'entryID:"entry1"}]';
	}
	this.getVolume = function() {
		return this.myplay.getVolume();
	}
	this.setVolume = function(value) {// 设置音量 －－田彦荣
		this.myplay.setVolume(parseInt(value));
	}
	this.getMuteFlag = function() {// 得到静音的值 －－田彦荣
		return this.myplay.getMuteFlag();
	}
	this.setMuteFlag = function(value) {// 设置静音的值 －－田彦荣
		this.myplay.setMuteFlag(parseInt(value));
	}
	this.getProgramLen = function() {
		return this.myplay.getMediaDuration();
	}
}

function OBJ(id) {
	return document.getElementById(id);
	/*
	 * if(!g_cacheid[id]){ g_cacheid[id]=document.getElementById(id); } return
	 * g_cacheid[id]?g_cacheid[id]:null;
	 */
}

// 频道号格式
var util = {
	/**
	 * util.date对象，用来放置与Date有关的工具
	 */
	str : {
		addZero : function(__str, __num) {
			__str = __str.toString();
			for ( var i = __str.length; i < __num; i++) {
				__str = "0" + __str;
			}
			return __str;
		},

		getDuration : function(__t1, __t2) {
			var t1 = __t1.split(":");
			var t2 = __t2.split(":");
			var duration = 0;
			duration = (Math.floor(t2[0]) * 60 + Math.floor(t2[1]))
					- (Math.floor(t1[0]) * 60 + Math.floor(t1[1]));
			if (t1[0] > t2[0])
				duration = duration + 1440;
			return duration;
		},

		millisecondToMinute : function(__mili) {
			return parseInt((__mili / 1000) / 60);
		},

		secondToStringTime : function(__sec) {
			var hour = Math.floor(__sec / 3600);
			var minute = Math.floor((__sec - hour * 3600) / 60);
			var second = __sec - hour * 3600 - minute * 60;
			hour = hour > 9 ? hour : "0" + hour;
			minute = minute > 9 ? minute : "0" + minute;
			second = second > 9 ? second : "0" + second;
			return hour + ":" + minute + ":" + second;
		},

		/**
		 * 根据传入的字符串日期和时间格式转换为毫秒的整数格式时间
		 * 
		 * @param string __str : 格式为“2008-09-01 14:00:00”的日期和时间字符串
		 * @return long int : 毫秒的时间格式
		 */
		stringDateTimeToMiliTime : function(__str) {
			var y = Math.floor(__str.substring(0, 4));
			var m = Math.floor(__str.substring(5, 7)) - 1;
			var d = Math.floor(__str.substring(8, 10));
			var t_h = Math.floor(__str.substring(11, 13));
			var t_m = Math.floor(__str.substring(14, 16));
			var t_s = Math.floor(__str.substring(17, 19));
			var my_date = new Date();
			my_date.setYear(y);
			my_date.setMonth(m);
			my_date.setDate(d);
			my_date.setHours(t_h);
			my_date.setMinutes(t_m);
			my_date.setSeconds(t_s);
			my_date.setMilliseconds(0);
			return my_date.getTime();
		},
		/*
		 * --------------------------- 功能 - 将输入字串前补add_string至设定宽度 参数 - arg1:
		 * 输入, 可以是字符串或数字 arg2: 欲补到多宽的字串 arg3: 欲补的字串，一般为一个字符
		 * ---------------------------
		 */
		toPaddedString : function(input, width, add_string) {
			var str = input.toString();
			while (str.length < width) {
				str = add_string + str;
			}
			return str;
		},

		undefinedReplacer : function(input, replace) {
			return (typeof (input) == "undefined") ? replace : input;
		}
	}
};
function clearCookie() {
	$.cookie("index_type_index", null);
	$.cookie("index_prefecture_index", null);
	$.cookie("index_prefecture_row", null);
	$.cookie("index_poster_index", null);
	$.cookie("index_user_index", null);
	$.cookie("menu_select_index", null);
	$.cookie("menu_index", null);
	$.cookie("map_index", null);

	$.cookie("v_select_map_index", null);
	$.cookie("v_left_index", null);
	$.cookie("v_class_index", null);
	$.cookie("v_content_Index", null);
	$.cookie("v_pageIndex", null);
	$.cookie('sho杨浩宇rogram', null, {
		path : '/'
	});
	$.cookie('programId', null, {
		path : '/'
	});
	$.cookie('startDate', null, {
		path : '/'
	});
	$.cookie('channelId', null, {
		path : '/'
	});
	$.cookie('catId', null, {
		path : '/'
	});
	$.cookie('ifTimeshiftplay', null, {
		path : '/'
	});

	deleteCookie("Cata_Index");
}
var shortcutkey = false;
function globalKey(val) {
	// alert(val);
	switch (val) {
	case 272: // 卓影
	{
		try {
			Authentication.CTCSetConfig("KeyValue", "0x110");
		} catch (e) {

		}
	}
	case 181: // 首页
	{
		shortcutkey = true;
		clearCookie();
		window.location.href = getRootPath_web() + "/index_epg.html";
	}
		break;
	case 275: // 直播
	{
		shortcutkey = true;
		clearCookie();
		window.location.href = getRootPath_web() + "/tv_play/index.html";
	}
		break;
	case 276: // 回看
	{
		shortcutkey = true;
		clearCookie();
		window.location.href = getRootPath_web() + "/tv_list/index.html";
	}
		break;
	case 277: // 点播
	{
		shortcutkey = true;
		clearCookie();
		window.location.href = getRootPath_web() + "/feast/feast.html?title="
				+ escape("电影") + "&folderid=26&time=" + Math.random();
	}
		break;
	default: {
		if (handleNumber == true)
			NumberKeyGlobal.handleKey(val);
	}
		break;
	}
}

var channelNumberDivGlobal = null;
var channelNameDivGlobal = null;
function showChannelGlobal(cnum, cname) {
	if (channelNumberDivGlobal == null && channelNameDivGlobal == null) {
		channelNumberDivGlobal = document.createElement("div");
		channelNumberDivGlobal.style.position = "absolute";
		channelNumberDivGlobal.style.left = "990px";
		channelNumberDivGlobal.style.top = "0px";
		channelNumberDivGlobal.style.width = "250px";
		channelNumberDivGlobal.style.height = "70px";
		channelNumberDivGlobal.style.lineHeight = "90px";
		channelNumberDivGlobal.style.textAlign = "right";
		channelNumberDivGlobal.style.background = "url(../images/alpha.png) repeat";
		channelNumberDivGlobal.style.color = "#00E1FC";
		channelNumberDivGlobal.style.fontSize = "46px";
		channelNumberDivGlobal.style.paddingRight = "40px";

		channelNameDivGlobal = document.createElement("div");
		channelNameDivGlobal.style.position = "absolute";
		channelNameDivGlobal.style.left = "990px";
		channelNameDivGlobal.style.top = "70px";
		channelNameDivGlobal.style.width = "250px";
		channelNameDivGlobal.style.height = "90px";
		channelNameDivGlobal.style.lineHeight = "90px";
		channelNameDivGlobal.style.textAlign = "right";
		channelNameDivGlobal.style.background = "url(../images/alpha.png) repeat";
		channelNameDivGlobal.style.color = "#00E1FC";
		channelNameDivGlobal.style.fontSize = "30px";
		channelNameDivGlobal.style.paddingRight = "40px";

		document.body.appendChild(channelNumberDivGlobal);
		document.body.appendChild(channelNameDivGlobal);
	}
	channelNumberDivGlobal.style.visibility = "visible";
	channelNameDivGlobal.style.visibility = "visible";
	channelNumberDivGlobal.innerHTML = cnum;
	channelNameDivGlobal.innerHTML = cname;
}

var channelMap = new Array();
var channellistGlobal = new Array();
var handleNumber = true;
getAuthChannel();

// 删除cookie
function deleteCookie(name) {
	var date = new Date();
	date.setTime(date.getTime() - 10000);
	document.cookie = name + "=v;path=/; expire=" + date.toGMTString();
}

function getAuth(name) {
	var num = Authentication.CTCGetConfig(name + "_num");// 分段数量
	var string = "";
	for ( var i = 1; i <= num; i++) {
		try {
			var code = name + "" + i;
			string += Authentication.CTCGetConfig(code);
		} catch (e) {
			alert(e);
		}
	}
	return decodeURI(string);
}

function setAuth(name, string) {
	if (string) {
		string = encodeURI(string);
		var msg = "";
		var dataLength = 4000;// 分段存储每段长度
		var num = Math.ceil(string.length / dataLength);// 分段数量
		Authentication.CTCSetConfig(name + "_num", num);// 分段数量
		for ( var i = 1; i <= num; i++) {
			var x = "";
			if (string.length - i * dataLength > 0) {
				x = string.substring((i - 1) * dataLength, i * dataLength);
			} else {
				x = string.substring((i - 1) * dataLength, string.length);
			}
			var code = name + "" + i;
			Authentication.CTCSetConfig(code, x);
		}
	}
}

function getChannelGlobal(handle) {
	if (handle == false) {
		handleNumber = false;
		return;
	}
	handleNumber = true;
	// var url = MY_PORTAL_ADDR+"/GetChannels";

	var channelGlobal;
	var update_from_server = false;
	try {
		// channelGlobal =
		// decodeURI(Authentication.CTCGetConfig("GlobalChannelList"));
		channelGlobal = getAuth("GlobalChannelList");
	} catch (e) {
		// alert("2:"+e);
	}
	if (channelGlobal != "" || typeof (update_from_server) == "undefine") {
		var channel_global_save = $.cookie('channel_global');
		if (channel_global_save == "yes") {
			update_from_server = false;
			// update_from_server = true;
		} else
			update_from_server = true;
	} else {
		update_from_server = true;
	}
	if (update_from_server == true) {
		// 获取频道
		var url = MY_PORTAL_ADDR + "/Channels";
		Ajax.request(url, {
			success : function(data) {
				$.cookie('channel_global', 'yes', {
					path : '/'
				});
				var string = JSON.stringify(data);
//				try {
					// Authentication.CTCSetConfig("GlobalChannelList",
					// encodeURI(string));
//					setAuth("GlobalChannelList", string);
//				} catch (e) {
//					alert("存GlobalChannelList：" + e);
//				}
				clearNoAuth(data);
				var AuthChannelList = JSON.stringify(data);
				try {
					// Authentication.CTCSetConfig("AuthChannelList",AuthChannelList);
					setAuth("AuthChannelList", AuthChannelList);
				} catch (e) {
					alert(e);
				}
				initChannelGlobal(data);
			},
			failure : function() {
				Ajax.request(url, {
					success : function(data) {
						$.cookie('channel_global', 'yes', {
							path : '/'
						});
						var string = JSON.stringify(data);
//						try {
//							setAuth("GlobalChannelList", string);
//						} catch (e) {
//							alert("存GlobalChannelList：" + e);
//						}
						clearNoAuth(data);
						var AuthChannelList = JSON.stringify(data);
						try {
							setAuth("AuthChannelList", AuthChannelList);
						} catch (e) {
							alert(e);
						}
						initChannelGlobal(data);
					},
					failure : function() {
					},
					type : "json"
				});
			},
			type : "json"
		});
		// getFavoritChannel();
	} else {
		initChannelGlobal(JSON.parse(channelGlobal));
	}
}

function initChannelGlobal(data) {
	var calc = 0;
	for ( var i = 0; i < data.channelGroups.length; i++) {
		if (data.channelGroups[i].groupId != "8") {
			for ( var j = 0; j < data.channelGroups[i].channels.length; j++) {
				// channellistMap.add(data.channelGroups[i].channels[j].channelNumber,data.channelGroups[i].channels[j]);
				channellistGlobal[calc++] = data.channelGroups[i].channels[j];
				if (!channellistMap
						.ContainsKey(data.channelGroups[i].channels[j].channelNumber)) {
					channellistMap.Add(
							data.channelGroups[i].channels[j].channelNumber,
							data.channelGroups[i].channels[j]);
				}
			}
		}
	}
}

function clearNoAuth(CGroup, type) {
	var channels = new Array();
	var num = 0;
	for ( var i = 0; i < CGroup.channelGroups.length; i++) {
		var calc = 0;
		for ( var j = 0; j < CGroup.channelGroups[i].channels.length; j++) {
			if (typeof (channelMap[CGroup.channelGroups[i].channels[j].channelCode]) == "undefined"
					|| isNaN(channelMap[CGroup.channelGroups[i].channels[j].channelCode])) {
				CGroup.channelGroups[i].channels.splice(j, 1);
				j--;
				continue;
			}
			CGroup.channelGroups[i].channels[j].is_pay = channelMap[CGroup.channelGroups[i].channels[j].channelCode];// 将是否订购加入data中
			calc++;
			if (CGroup.channelGroups[i].channels[j].is_pay == 0) {
				channels[num] = CGroup.channelGroups[i].channels[j];
				num++;
			}
		}
		if (calc == 0) {
			// CGroup.channelGroups.splice(i,1);
			// i--;
		}
	}
	// alert("channels："+JSON.stringify(channels));
	// CGroup.channelGroups[8]=new Object();
	// CGroup.channelGroups[8].groupName="订购";
	// CGroup.channelGroups[8].groupId=10;
	// if(typeof(type!="undefined")&&type=="no"){
	// try{
	// CGroup.channelGroups[8].channels=channelArea.channelGroupData[10];
	// for(var i in CGroup.channelGroups[8].channels)
	// {
	// var ifHas="0";
	// if(channels.length>0){
	// for(var j in channels){
	// if(CGroup.channelGroups[8].channels[i].channelCode==channels[j].channelCode){
	// ifHas="1";
	// }
	// }
	// }else{
	// }
	// if(ifHas=="0"){
	// //原始订购类下的频道中没有在新订购类下没有的频道，设置为已订购
	// CGroup.channelGroups[8].channels[i].is_pay=1;
	// }
	// }
	// }catch(e){
	//			
	// }
	// }else{
	// alert("产生订购类别");
	// CGroup.channelGroups[8].channels=channels;
	// CGroup.channelGroups[8].channels.sort(function(a,b){
	// return parseInt(a.channelNumber)-parseInt(b.channelNumber);
	// });

	CGroup.channelGroups.sort(function(a, b) {
		if (a.channels.length == 0)
			return 1;
		if (b.channels.length == 0)
			return 1;
		var x = parseInt(a.channels[0].channelNumber)
				- parseInt(b.channels[0].channelNumber);
		return x;
	});
}
function getAuthChannel() {
	var channellistStr = "";
	try {
		channellistStr = Authentication.CTCGetConfig("UsableChannel");
	} catch (e) {
		channellistStr = '00000001000000050000000000000197,1|00000001000000050000000000000055,1|90000001000000050000000000000200,0|00000001000000050000000000000067,1|99221000000000050000000000000431,1|90000001000000050000000000000180,1|90000001000000050000000000000211,1|00000001000000050000000000000118,1|00000001000000050000000000000062,1|00000001000000050000000000000149,0|00005000000000000000000000000263,1|99221000000000050000000000000431,0|99221000000000050000000000000352,1|00000001000000050000000000000070,1|00000001000000050000000000000084,0';
	}
	var channellistID = channellistStr.split("|");
	var channelStr = "";
	for ( var i = 0; i < channellistID.length; i++) {
		channelStr = channellistID[i].split(",");
		// for(var j=0; j < channelStr.length; j++){
		// var start = 0;
		// var firstEqual = channelStr[j].indexOf("=");
		// var paraName = channelStr[j].substring(0, firstEqual);
		// var paraValue = channelStr[j].substring(firstEqual+2,
		// channelStr[j].length-1);
		// if(paraName == "ChannelID"){
		channelMap[channelStr[0]] = parseInt(channelStr[1]);
		// }
		// }
	}
	return channelMap;
}

function getFavoritChannel() {
	// 获取收藏的频道
	var url = MY_PORTAL_ADDR + "/GetFavorits?type=1&pageSize=300&userFlag="
			+ getUserID();
	Ajax.request(url, {
		success : function(data) {
			var FavoritChannelList = JSON.stringify(data.channelschannels);
			try {
				getAuth("FavoritChannelList", FavoritChannelList);
			} catch (e) {
			}
		},
		failure : function() {
			Ajax.request(url, {
				success : function(data) {
					var FavoritChannelList = JSON
							.stringify(data.channelschannels);
					try {
						setAuth("FavoritChannelList", FavoritChannelList);
					} catch (e) {
					}
				},
				failure : function() {
				},
				type : "json"
			});
		},
		type : "json"
	});
}

// 更新频道鉴权信息，在订购频道后调用该函数
function updateChannelList(type) {
	var url = MY_PORTAL_ADDR + "/UpdateChannelList?userID=" + getUserID();
	Ajax.request(url, {
		success : function(data) {
			try {
				// Authentication.CTCSetConfig("UsableChannel",data.channelList);
				var channellistID = data.channelList.split("|");
				var channelStr = "";
				// alert("channellistID:"+channellistID);
				for ( var i = 0; i < channellistID.length; i++) {
					channelStr = channellistID[i].split(",");
					channelMap[channelStr[0]] = parseInt(channelStr[1]);
				}
			} catch (e) {
				alert(e);
			}
			try {
				// var data =
				// decodeURI(Authentication.CTCGetConfig("GlobalChannelList"));
				var data = getAuth("GlobalChannelList");
				data = JSON.parse(data);
				clearNoAuth(data, "no");
				var AuthChannelList = JSON.stringify(data);
				// Authentication.CTCSetConfig("AuthChannelList",
				// AuthChannelList);
				setAuth("AuthChannelList", AuthChannelList);
				if (type == 1) {
					checkChannels("no");
				}
			} catch (e) {
				alert("1:" + e);
			}
		},
		failure : function() {

		},
		type : "json"
	});
}

function updateProduct() {
	Ajax.request(MY_PORTAL_ADDR + "/EpgAuth?userToken=" + getUserToken(), {
		success : function(data) {
			result = parseInt(data.result);
			if (result == 0) {
				$.cookie("userId", data.userId);
				$.cookie("epgGroupNMB", data.epgGroupNMB);
				$.cookie("userGroupNMB", data.userGroupNMB);
				$.cookie("stbID", data.stbID);
				$.cookie("mac", data.mac);
				$.cookie("products", data.products, {
					path : '/'
				});
				Authentication.CTCSetConfig("products", data.products);
				$.cookie("tokenExpireTime", data.tokenExpireTime);
			} else {

			}
		},
		failure : function(XMLHttpRequest, textStatus, errorThrown) {
		},
		type : "json"
	});
}

function getSTBID() {
	var stbNo = "123";
	try {
		stbNo = Authentication.CTCGetConfig("STBID");
	} catch (e) {

	}
	return stbNo;
}

var NumberKeyGlobal = function() {
	var o = {};
	o.currentKey = 0;
	o.isNumberKey = false;
	o.showTimer = null;
	o.currentIndex = 0;
	o.currentCataIndex = 0;
	o.clearHandle = function() {
		if (o.showTimer != null)
			clearTimeout(o.showTimer);
		o.currentKey = 0;
		o.isNumberKey = false;
		o.showTimer = null;
	}
	o.checkChannel = function(keynum) {
		for ( var i = 0; i < channellistGlobal.length; i++) {
			if (keynum == parseInt(channellistGlobal[i].channelNumber)) {
				o.currentIndex = i;
				o.currentCataIndex = 0;
				return i;
			}
		}
		o.currentIndex = -1;
		return -1;
	}
	o.showNumber = function() {
		if (o.currentKey > 999) {
			o.currentKey = o.currentKey % 10;
		}

		var showName = "";
		if (o.showTimer != null)
			clearTimeout(o.showTimer);
		if (!channellistMap.ContainsKey(o.currentKey)) {
			showName = "<span style='color:#FF0000'>无此频道</span>";
			o.showTimer = setTimeout(o.hideNumber, 3000);
		} else {
			showName = channellistMap.TryGetValue(o.currentKey).channelName;
			o.showTimer = setTimeout(o.jumpPlay, 1500);
		}
		showChannelGlobal(util.str.addZero(o.currentKey, 3), showName);
	}
	o.jumpPlay = function() {
		var ids = channellistMap.TryGetValue(o.currentKey).channelId;// channellistGlobal[o.currentIndex].channelId;
		window.location.href = getRootPath_web() + "/tv_play/index.html?"
				+ "channelid=" + ids + "&cata_id=0";
		o.showTimer = setTimeout(o.hideNumber, 3000);
		o.currentKey = 0;
	}
	o.hideNumber = function() {
		o.isNumberKey = false;
		channelNumberDivGlobal.style.visibility = "hidden";
		channelNameDivGlobal.style.visibility = "hidden";
		o.currentKey = 0;
	}
	o.handleKey = function(nkey) {
		switch (nkey) {
		case ROC_IRKEY_NUM1:
		case ROC_IRKEY_NUM2:
		case ROC_IRKEY_NUM3:
		case ROC_IRKEY_NUM4:
		case ROC_IRKEY_NUM5:
		case ROC_IRKEY_NUM6:
		case ROC_IRKEY_NUM7:
		case ROC_IRKEY_NUM8:
		case ROC_IRKEY_NUM9:
			// GF_WebPrint(nkey);
			if (!o.isNumberKey) {
				o.isNumberKey = true;
				o.currentKey = nkey - ROC_IRKEY_NUM0;
			} else {
				o.currentKey = o.currentKey * 10 + (nkey - ROC_IRKEY_NUM0);
			}
			o.showNumber();
			break;
		case ROC_IRKEY_NUM0:
			// GF_WebPrint(nkey);
			if (o.isNumberKey) {
				if (o.currentKey > 0) {
					o.currentKey = o.currentKey * 10;
					o.showNumber();
				}
			}
			break;
		default:
			return;
		}
	}
	return o;
}();
function getRootPath_web() {
//	 获取当前网址，如： http://localhost:8083/uimcardprj/share/meun.jsp
//	 var curWw杨浩宇ath = window.document.location.href;
//	 获取主机地址之后的目录，如： uimcardprj/share/meun.jsp
//	 var pathName = window.document.location.pathname;
//	 var pos = curWw杨浩宇ath.indexOf(pathName);
//	 获取主机地址，如： http://localhost:8083
//	 var localhostPaht = curWw杨浩宇ath.substring(0, pos);
//	 获取带"/"的项目名，如：/uimcardprj
//	 var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') +
//	 1);
//	 alert(localhostPaht + projectName);
//	 return (localhostPaht + projectName);
	return $.cookie("iptvWebName");
}

function getRoot() {
	// 获取当前网址，如： http://localhost:8083/uimcardprj/share/meun.jsp
	var curWw杨浩宇ath = window.document.location.href;
	// 获取主机地址之后的目录，如： uimcardprj/share/meun.jsp
	var pathName = window.document.location.pathname;
	var pos = curWw杨浩宇ath.indexOf(pathName);
	// 获取主机地址，如： http://localhost:8083
	var localhostPaht = curWw杨浩宇ath.substring(0, pos);
	// 获取带"/"的项目名，如：/uimcardprj
	var projectName = pathName
			.substring(0, pathName.substr(1).indexOf('/') + 1);
	// alert(localhostPaht + projectName);
	return localhostPaht;
}

/** 消息 */
var messageConent = function MessageConent() {
	var o = {};
	var msgIntervalID = 0; // 时间计时器
	o.init = function() {
		o.msgStart();
	}
	o.unload = function() {
		o.msgStop();
	}
	o.msgStart = function() {
		if (typeof (pushMsgJson) != "undefined") {

			try {
				msgIntervallID = setTimeout(
						function() {
							$("#messageConent").remove();
							var now = new Date();
							var content = " ";
							$.each(pushMsgJson, function(name, value) {
								var name = name;
								var msg = value;
								msg.pushStartTime;
								var start = new Date(msg.pushStartTime.replace(
										"-", "/").replace("-", "/"));
								var end = new Date(msg.pushEndTime.replace("-",
										"/").replace("-", "/"));
								if (start <= now && now <= end) {
									content += msg.pushMsg + "  ";
								}
							});
							var html = '<marquee id="messageConent" style="height: 40px; width: 1170px; color: #fff; position: absolute; top: 480px;  left: 61px; font-size: 30px; z-index: 20000;" direction=left behavior=scroll scrollamount=6 scrolldelay=10>'
									+ content + '</marquee>'

							$("#index").append(html);
							msgIntervallID = setTimeout(arguments.callee,
									300000);
						}, 1000);
			} catch (e) {
				// TODO: handle exception
			}
		}
	}
	o.msgStop = function() {
		clearTimeout(msgIntervallID);
	}
	return o;
}();
messageConent.init();
// 系统消息处理
var redirectFlag = false;// 灾备中播放重定向标志，0未重定向，1重定向
function sysinfohandle() {
	this.playEnd = function() {
	};
	this.playStart = function() {
	};
	this.playRedirect = function() {
	};
	this.broadcastPlay = function() {
	};
	this.playtochannel = function() {
	};// 回看到直播
	this.showSysError = function(content) {
		var objdiv = $("syswin");
		if (objdiv == null) {// 层不存在
			var divObj = document.createElement("div");
			divObj.innerHTML = "<div id='syswin' class='sysTip'><div id='errortip'>"
					+ content + "</div></div>";
			document.body.appendChild(divObj);
		} else {
			objdiv.style.visibility = "visible";
			objdiv.innerHTML = "<div id='errortip'>" + content + "</div>";
		}
	}
}
var sysEventHandle = new sysinfohandle(); // 实例化消息处理对象

// 获取URL"?"后面的字符串 && //类型简单判断
var $G = {
	"getParameter" : function(param) {
		var query = window.location.search; // 获取URL"?"后面的字符串
		if (query.length == 0) {
			return "";
		} else {
			var iLen = param.length;
			var iStart = query.indexOf(param);

			if (iStart == -1) // 判断是否有那个需要查询值的传递参数
				return ""; // 没有就返回一个空值
			iStart += iLen + 1;

			var iEnd = query.indexOf("&", iStart); // 判断是不是带有多个参数 &为多个参数的连接符号
			if (iEnd == -1) {
				return query.substring(iStart);
			}
			return query.substring(iStart, iEnd);
		}
	}
}
// 获取页面的ID元素
function getThis(id) {
	return document.getElementById(id);
	/*
	 * if(!g_cacheid[id]){ g_cacheid[id]=document.getElementById(id); } return
	 * g_cacheid[id]?g_cacheid[id]:null;
	 */
}
// 获得cookie
function getCookie(name) {
	var strCookie = document.cookie;
	var arrCookie = strCookie.split("; ");
	for ( var i = 0; i < arrCookie.length; i++) {
		var arr = arrCookie[i].split("=");
		if (arr[0] == name)
			return arr[1];
	}
	return "";
}
// 删除cookie
function deleteCookie(name) {
	var date = new Date();
	date.setTime(date.getTime() - 10000);
	document.cookie = name + "=v;path=/; expire=" + date.toGMTString();
}